package com.example.day09d_1;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private ViewPager mVp;
    private TabLayout mTab;
    private ArrayList<Fragment> fragments;
    private FragmentManager manager;
    private Frag_Adapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }


    private void initView() {
        mVp = (ViewPager) findViewById(R.id.vp);
        mTab = (TabLayout) findViewById(R.id.tab);
        fragments = new ArrayList<>();
        fragments.add(new Recy_Fragment());
        fragments.add(new WebviewFragment());
        fragments.add(new SqlFragment());
        manager = getSupportFragmentManager();
        adapter = new Frag_Adapter(manager, fragments);
        mVp.setAdapter(adapter);
        mTab.setupWithViewPager(mVp);

        mTab.getTabAt(0).setText("首页");
        mTab.getTabAt(1).setText("我的");
        mTab.getTabAt(2).setText("数据库");

    }
}
